package com.xy.singleresponsibility;

/**
 * @author 谢阳
 * @version 1.8.0_131
 * @date 2022/6/7 9:45
 * @description 单一职责方案二
 */

public class SingleResponsibility2 {
    public static void main(String[] args) {
        RoadVehicle roadVehicle = new RoadVehicle();
        roadVehicle.run("摩托");
        roadVehicle.run("汽车");
        AirVehicle airVehicle = new AirVehicle();
        airVehicle.run("飞机");
    }
}


/**
 * 方案2的分析
 *  1.遵守了单一职责原则
 *  2.改动大，即将类分解，同时修改客户端
 *  3.优化：方案3
 */

class RoadVehicle {
    public void run(String vehicle) {
        System.out.println(vehicle + "公路运行");
    }
}

class AirVehicle {
    public void run(String vehicle) {
        System.out.println(vehicle + "空中运行");
    }
}

class WaterVehicle {
    public void run(String vehicle) {
        System.out.println(vehicle + "水中运行");
    }
}